﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using DevTeam;
using System.Data;

namespace ConfExpert.Forms.Rapor.Etiketler
{
    public partial class EtiketRaf4 : DevReport
    {
        private DataSet dsRaf { get; set; }
        public EtiketRaf4()
        {
            InitializeComponent();

            dsRaf = ExecuteDataSet("GetBarcodeRAF2");

            Bind();

            tcRaf.BeforePrint += tcRaf_BeforePrint;
        }

        private void Bind()
        {
            this.DataMember = "Table";
            this.DataSource = dsRaf;

            tcRaf.DataBindings.Add("Text", null, "Table.Yeni");
            tcEskiRaf.DataBindings.Add("Text", null, "Table.Eski");
            barcodeRaf.DataBindings.Add("Text", null, "Table.ShelfId1e9");
        }

        void tcRaf_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            float newSize = 72F;
            label.Font = new Font("Century", newSize, FontStyle.Regular);

            float stringWidth = gr.MeasureString(label.Text, label.Font).Width;
            float labelWidth = label.HeightF;


            if (labelWidth < stringWidth * factor)
                newSize = label.Font.Size * label.HeightF / stringWidth / factor;

            label.Font = new Font("Century", newSize, FontStyle.Regular);
            gr.Dispose();
        }
    }
}
